package com.ec.bl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ec.bl.domain.dto.RefundRecordDTO;
import com.ec.bl.domain.dto.RefundApprovalRequest;
import com.ec.bl.domain.dto.RefundQueryRequest;
import com.ec.bl.domain.dto.RefundRequest;
import com.ec.bl.service.RefundRecordService;
import com.ec.common.domain.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/admin/refund")
@RequiredArgsConstructor
public class RefundRecordController {

    private final RefundRecordService refundRecordService;

    /**
     * 创建退款申请
     */
    @PostMapping("/create")
    public Result<Long> createRefundRequest(@Valid @RequestBody RefundRequest request) {
        return refundRecordService.createRefundRequest(request);
    }

    /**
     * 分页查询退款记录
     */
    @GetMapping("/page")
    public Result<IPage<RefundRecordDTO>> getRefundRecordPage(RefundQueryRequest query) {
        return refundRecordService.getRefundRecordPage(query);
    }

    /**
     * 根据ID查询退款记录详情
     */
    @GetMapping("/{id}")
    public Result<RefundRecordDTO> getRefundRecordById(@PathVariable Long id) {
        return refundRecordService.getRefundRecordById(id);
    }

    /**
     * 审核退款申请
     */
    @PostMapping("/approve")
    public Result<Boolean> approveRefundRequest(@Valid @RequestBody RefundApprovalRequest request) {
        return refundRecordService.approveRefundRequest(request);
    }

    /**
     * 完成退款
     */
    @PostMapping("/complete/{refundId}")
    public Result<Boolean> completeRefund(@PathVariable Long refundId) {
        return refundRecordService.completeRefund(refundId);
    }

    /**
     * 查询用户的退款记录
     */
    @GetMapping("/user/{elderlyUserId}")
    public Result<List<RefundRecordDTO>> getRefundRecordsByUserId(@PathVariable Long elderlyUserId) {
        return refundRecordService.getRefundRecordsByUserId(elderlyUserId);
    }

    /**
     * 删除退款记录
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteRefundRecord(@PathVariable Long id) {
        return refundRecordService.deleteRefundRecord(id);
    }
}